package com.chinasoft.goodsManager.servlet;

import com.chinasoft.goodsManager.domain.Manager;
import com.chinasoft.goodsManager.service.LoginService;
import com.chinasoft.goodsManager.service.impl.LoginServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

@WebServlet("/updateManagerInformation")
public class UpdateManagerInformationServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        LoginService loginService = new LoginServiceImpl();
        //设置请求字符集编码，防止乱码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String mname = request.getParameter("mname");
        String mage = request.getParameter("mage");
        String mcity = request.getParameter("mcity");
        String maddress = request.getParameter("maddress");
        String mphone = request.getParameter("mphone");
        HttpSession session = request.getSession();
        Manager manager = (Manager) session.getAttribute("manager");
        Manager newManager= loginService.updateManagerInformation(manager,mname,mage,mcity,maddress,mphone);
        session.setAttribute("manager",newManager);
        response.getWriter().write("修改成功");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
